//package edu.wpi.first.wpilibj.templates.subsystems;
//
//import edu.wpi.first.wpilibj.DriverStationLCD;
//import edu.wpi.first.wpilibj.camera.AxisCamera;
//import edu.wpi.first.wpilibj.camera.AxisCameraException;
//import edu.wpi.first.wpilibj.command.Subsystem;
//import edu.wpi.first.wpilibj.image.ColorImage;
//import edu.wpi.first.wpilibj.image.MonoImage;
//import edu.wpi.first.wpilibj.image.NIVisionException;
//
///**
// * author Jarrod Risley
// * Prototype Camera Subsystem, meant to give us some manual 
// * control over certain aspects of the camera itself.
// * Currently, allocations have been made for the extraction
// * of the Luminance plane to find some bright areas of an
// * image. Other than that, no further "tracking" stuff has
// * been created. This should serve as an "eh" template for
// * future camera systems.
// */
//
///*
// * Note: All functions check to see if isCameraActive is true or not. This is a 
// * simple way to keep the bot running in the event that the camera is not initialized
// * correctly.
// */
//
//
//public class VisualTrackingSubsystem extends Subsystem {
//    // Put methods for controlling this subsystem
//    // here. Call these from Commands.
//    
//    AxisCamera camera; // setup for this is weird. Not like usual "set to null" thing.
//    boolean isCameraActive = false;
//    String address;
//    String CameraName;
//    private int brightnessLevel;
//    private int framesPerSecond;
//    public int kColorLevel;
//    private int luminanceValue;
//    ColorImage image;
//    private MonoImage lumPlane;
//    private boolean isLumPlaneActive = false;
//    
//    public void initDefaultCommand() {
//        // Set the default command for a subsystem here.
//        //setDefaultCommand(new MySpecialCommand());
//        setDefaultCommand(null);
//    }
//    
//    public VisualTrackingSubsystem(String name, String ip) {
//        ip = address;
//        name = CameraName;
//        camera = AxisCamera.getInstance(); // Sets the IP adress.
//        if (camera.equals(address)) {
//            isCameraActive = true;
//            System.out.println("VisualTrackingSubsystem " + CameraName + "created.");
//        } else {
//            isCameraActive = false;
//            System.out.println("Error creating VisualTrackingSubsystem: " + CameraName
//                    + ". ");
//            System.out.println("-----CAMERA OFFLINE-----");
//        }
//    }
//    
//    
//    public void setBrightness(int level) {
//        if (isCameraActive) {
//            level = brightnessLevel;
//            camera.writeBrightness(brightnessLevel);
//        }
//    }
//    
//    // Automatically sets
//    public void setWhiteBalance() {
//        if (isCameraActive) {
//            camera.writeWhiteBalance(AxisCamera.WhiteBalanceT.automatic);
//        }
//    }
//    
//    public void setFramesPerSecond(int fps) {
//        if (isCameraActive) {
//        fps = framesPerSecond;
//        camera.writeMaxFPS(framesPerSecond);
//        }
//    }
//    
//    public void setResolution() {
//        if (isCameraActive) {
//        camera.writeResolution(AxisCamera.ResolutionT.k640x480); // could be declared globally?
//        }
//    }
//    
//    public void updateDashboard() {
//        if (isCameraActive) {
//        DriverStationLCD.getInstance().updateLCD();
//        }
//    }
//     
//    // getImage() frees image automatically.
//    public void getImage() throws AxisCameraException, NIVisionException {
//        if (isCameraActive) {
//            if (false == camera.freshImage()) {
//                image = camera.getImage();
//                DriverStationLCD.getInstance().updateLCD();
//            } else {
//                kColorLevel = camera.getColorLevel();
//                image.replaceLuminancePlane(lumPlane);
//                isLumPlaneActive = true;
//                System.out.println(lumPlane);
//                image.free();
//            }
//        }
//    }
//    
//    public void findLuminance() throws AxisCameraException, NIVisionException {
//        if ((isCameraActive) && (isLumPlaneActive)) {
//            image.replaceLuminancePlane(lumPlane);
//            System.out.println(lumPlane);
//        } else if (false == isCameraActive) {
//            System.out.println("Error: " + CameraName + " not active.");
//        } else if (false == isLumPlaneActive) {
//            System.out.println("Error: Luminance plane replacement failed"
//                    + " --- lumPlane not extracted.");
//        } else if ((false == isCameraActive) && (false == isLumPlaneActive)) {
//            System.out.println("Error: " + CameraName + "not active and "
//                    + "Luminance plane replacement failed --- "
//                    + "lumPlane not extracted.");
//        }
//    }
//    
///*
//* ***************************WARNING************************************ 
//*                THE FOLLOWING IS AN ABSOLUTE MUST:
//* 
//* Whenever you call forth an image, you need to make sure that after
//* all operations have been completed on the image (i.e. extract 
//* Luminance plane, find a square targe, and so forth), the image itself 
//* MUST BE DELETED. Otherwise epic sad face will occur. We don't want
//* epic sad face. So when you're done, call this function - this takes
//* care of this for you, so you can go track your square :D
//*/
//
//    public void deleteImage() throws NIVisionException {
//        image.free(); // Deletes the image. CALL THIS LAST.
//    }
//    
//}
